<!DOCTYPE html>

<html>
<head>
  <title>Stream</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  <link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
  <div id="container">
    <div id="background"></div>
    
      <ul id="jump_to">
        <li>
          <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
          <a class="small" href="javascript:void(0);">+</a>
          <div id="jump_wrapper">
          <div id="jump_page">
            
              
              <a class="source" href="List.coffee.html">
                List.coffee.md
              </a>
            
              
              <a class="source" href="Map.coffee.html">
                Map.coffee.md
              </a>
            
              
              <a class="source" href="Record.coffee.html">
                Record.coffee.md
              </a>
            
              
              <a class="source" href="Set.coffee.html">
                Set.coffee.md
              </a>
            
              
              <a class="source" href="Stream.coffee.html">
                Stream.coffee.md
              </a>
            
              
              <a class="source" href="Tuple.coffee.html">
                Tuple.coffee.md
              </a>
            
              
              <a class="source" href="header.coffee.html">
                header.coffee.md
              </a>
            
          </div>
        </li>
      </ul>
    
    <ul class="sections">
        
        
        
        <li id="section-1">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-1">&#182;</a>
              </div>
              <h1 id="stream">Stream</h1>

            </div>
            
            <div class="content"><div class='highlight'><pre>	
	<span class="hljs-built_in">window</span>.Stream = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Stream</span></span>

		<span class="hljs-attribute">constructor</span>:<span class="hljs-function"> -&gt;</span>
			<span class="hljs-property">@fns</span> = []
		
		<span class="hljs-attribute">add</span>: Function.Chaining <span class="hljs-function"><span class="hljs-params">(first,rest...)</span> -&gt;</span> fn.call first, first, rest... <span class="hljs-keyword">for</span> fn <span class="hljs-keyword">in</span> <span class="hljs-property">@fns</span>
		
		<span class="hljs-attribute">each</span>: Function.From(Function) \
			<span class="hljs-function"><span class="hljs-params">(fn)</span> -&gt;</span> <span class="hljs-property">@fns</span>.push fn
		
		<span class="hljs-attribute">derive</span>: Function.From(Function).Returning(<span class="hljs-function">-&gt;</span> <span class="hljs-keyword">new</span> <span class="hljs-property">@constructor</span>() ) \
			<span class="hljs-function"><span class="hljs-params">(child)</span> -&gt;</span> <span class="hljs-function"><span class="hljs-params">(fn)</span> -&gt;</span> <span class="hljs-property">@each</span> fn.bind child</pre></div></div>
            
        </li>
        
        
        <li id="section-2">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-2">&#182;</a>
              </div>
              <h1 id="typed-streams">Typed streams</h1>

            </div>
            
            <div class="content"><div class='highlight'><pre>		
		<span class="hljs-property">@Of</span>: Function.Cache.From<span class="hljs-function"><span class="hljs-params">(Function)</span>.<span class="hljs-title">To</span><span class="hljs-params">(Function)</span> <span class="hljs-params">(constructor)</span> -&gt;</span>
			<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">this</span></span>
				<span class="hljs-attribute">add</span>: Function.Of(constructor) <span class="hljs-attribute">this</span>::add</pre></div></div>
            
        </li>
        
        
        <li id="section-3">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-3">&#182;</a>
              </div>
              <h2 id="derived-streams">Derived streams</h2>

            </div>
            
            <div class="content"><div class='highlight'><pre>		
		<span class="hljs-attribute">map</span>: Function.From(Function).To(Stream) \
			<span class="hljs-function"><span class="hljs-params">(fn)</span> -&gt;</span> <span class="hljs-property">@derive</span> <span class="hljs-function"><span class="hljs-params">(first,rest...)</span> -&gt;</span> <span class="hljs-property">@add</span> fn.call first, first, rest...
		
		<span class="hljs-attribute">where</span>: Function.From(Function).To(Stream) \
			<span class="hljs-function"><span class="hljs-params">(predicate)</span> -&gt;</span> <span class="hljs-property">@derive</span> <span class="hljs-function"><span class="hljs-params">(first,rest...)</span> -&gt;</span>
				<span class="hljs-property">@add</span> first, rest... <span class="hljs-keyword">if</span> predicate.call first, first, rest...
		
		<span class="hljs-attribute">take</span>: Function.From(Number).To(Stream) \
			<span class="hljs-function"><span class="hljs-params">(number)</span> -&gt;</span> <span class="hljs-property">@where</span><span class="hljs-function"> -&gt;</span> number-- &gt; <span class="hljs-number">0</span>
		
		<span class="hljs-attribute">drop</span>: Function.From(Number).To(Stream) \
			<span class="hljs-function"><span class="hljs-params">(number)</span> -&gt;</span> <span class="hljs-property">@where</span><span class="hljs-function"> -&gt;</span> --number &lt; <span class="hljs-number">0</span>
		
		<span class="hljs-attribute">transition</span>: Function.To(Stream) \<span class="hljs-function">
			-&gt;</span> <span class="hljs-keyword">do</span> <span class="hljs-function"><span class="hljs-params">(last=<span class="hljs-literal">undefined</span>)</span> =&gt;</span>
				<span class="hljs-property">@where</span> <span class="hljs-function"><span class="hljs-params">(x)</span> -&gt;</span> Boolean (<span class="hljs-keyword">not</span> Value.equal(x,last) ) <span class="hljs-keyword">and</span> ( ( last = x ) <span class="hljs-keyword">or</span> <span class="hljs-literal">true</span> )
				
		<span class="hljs-attribute">control</span>: Function.From(Stream).To(Stream) \
			<span class="hljs-function"><span class="hljs-params">(control)</span> -&gt;</span> <span class="hljs-keyword">do</span> <span class="hljs-function"><span class="hljs-params">(active=<span class="hljs-literal">true</span>)</span> =&gt;</span>
				control.each Function.Of<span class="hljs-function"><span class="hljs-params">(Boolean)</span> <span class="hljs-params">(state)</span> -&gt;</span> active = state
				<span class="hljs-property">@where</span><span class="hljs-function"> -&gt;</span> active
				
		<span class="hljs-attribute">between</span>: Function.From(Stream,Stream).To(Stream) \
			<span class="hljs-function"><span class="hljs-params">(start,stop)</span> -&gt;</span>
				<span class="hljs-property">@control</span> Stream.disjoin \
					start.map(Boolean.True),
					stop.map(Boolean.False)
					
		<span class="hljs-attribute">accumulate</span>: Function.From(Function,Maybe Value).To(Stream) \
			<span class="hljs-function"><span class="hljs-params">(reduction,initial=reduction.unit)</span> -&gt;</span> <span class="hljs-keyword">do</span> <span class="hljs-function"><span class="hljs-params">(acc=initial)</span> =&gt;</span>
				<span class="hljs-property">@derive</span> <span class="hljs-function"><span class="hljs-params">(args...)</span> -&gt;</span>
					<span class="hljs-property">@add</span> acc = reduction.call <span class="hljs-keyword">this</span>, acc, args...</pre></div></div>
            
        </li>
        
        
        <li id="section-4">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-4">&#182;</a>
              </div>
              <h2 id="stream-combinators">Stream combinators</h2>

            </div>
            
            <div class="content"><div class='highlight'><pre>		
		<span class="hljs-property">@disjoin</span>: Function.From([Stream]).Returning(<span class="hljs-function">-&gt;</span> <span class="hljs-keyword">new</span> Stream) \
			<span class="hljs-function"><span class="hljs-params">(disjunction)</span> -&gt;</span> <span class="hljs-function"><span class="hljs-params">(streams...)</span> -&gt;</span>
				<span class="hljs-keyword">for</span> stream <span class="hljs-keyword">in</span> streams
					stream.each <span class="hljs-function"><span class="hljs-params">(args...)</span> -&gt;</span> disjunction.add args...</pre></div></div>
            
        </li>
        
    </ul>
  </div>
</body>
</html>
